﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nplJobsCommon.Common;
using System.Data;
using System.Data.SqlClient;

namespace nplJobsDAL.Select
{
    public class SelectDistrict : DataAccessBase
    {
        public int DivisionId
        {
            get;
            set;
        }

        public SelectDistrict()
        {
            StoredProcedureName = StoredProcedure.Name.spGetDistrict.ToString();
        }

        #region GetCity
        public List<District> GetDistrict()
        {
            DataBaseHelper dbHelper;
            DataSet dsDistrict;

            try
            {
                SelectDivisionParameters parameters = new SelectDivisionParameters(DivisionId);
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dbHelper.Parameters = parameters.Parameters;
                dsDistrict = dbHelper.Run(base.ConnectionString, dbHelper.Parameters);
                return GetList(dsDistrict);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<District> GetList(DataSet dsDistrict)
        {
            List<District> districts;
            try
            {
                districts = (from n in dsDistrict.Tables[0].AsEnumerable()
                             select new District
                                {
                                    ID = n.Field<int>("ID"),
                                    Name = n.Field<string>("Name")
                                }).ToList();

                return districts;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion

        #region SQL parameters for selecting cities by country
        public class SelectDivisionParameters
        {
            public int CkeckUnique;
            private SqlParameter[] _parameters;

            public SelectDivisionParameters(int divisionID)
            {
                this.DivisionID = divisionID;
                Build();
            }

            #region spAddContact parameters
            /*
         
         */
            #endregion

            private void Build()
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter("@DivisionID", DivisionID),
                };

                Parameters = parameters;
            }

            public int DivisionID { get; set; }

            public SqlParameter[] Parameters
            {
                get { return _parameters; }
                set { _parameters = value; }
            }
        }
        #endregion
    }
}
